﻿using System.IO;
using System.Web;
using System.Web.Mvc;
using Zhang.AdminPage;
using Document = Spire.Doc.Document;
using Paragraph = Spire.Doc.Documents.Paragraph;
using Section = Spire.Doc.Section;


namespace Zhang.Admin.Controllers
{
    public class InterviewController : BaseController
    {
        // GET: Blogger
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Add()
        {
            return View();
        }

        public ActionResult Import()
        {
            return View();
        }

        private string StorageRoot
        {
            get { return Path.Combine(Server.MapPath("~/Files")); }//文件上传的路径：根目录下的/Files 文件夹
        }
        /// <summary>
        /// 上传word文件
        /// </summary>
        [HttpPost]
        public ActionResult UploadFiles()
        {
            bool ret = false;
            var headers = Request.Headers;
            var Message = "";
            if (string.IsNullOrEmpty(headers["X-File-Name"]))
            {
                ret = UploadWholeFile(Request, out Message);//上传文件
            }
            ViewBag.Message = Message.Replace("\r\n", "#");
            ViewBag.Result = ret;
            return View("Index");
        }

        private bool UploadWholeFile(HttpRequestBase request, out string Message)
        {
            Message = "";
            var type = request.Form["type"];
            var file = request.Files[0];//文件源
            var fullPath = Path.Combine(StorageRoot, Path.GetFileName(file.FileName));//服务器文件完整路径
            file.SaveAs(fullPath);//复制文件


            Document doc = new Document();
            doc.LoadFromFile(fullPath);

            //遍历章节
            foreach (Section section in doc.Sections)
            {
                //遍历段落
                foreach (Paragraph paragraph in section.Paragraphs)
                {
                    //判断段落样式是否为Heading 2
                    if (paragraph.StyleName == "Heading2")
                    {
                        //输出标题2对应的文本
                       var aa= paragraph.Text;
                    }
                }
            }


            return false;

        }
    }
}